﻿namespace ExamV5.ZiExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmEditRubricDoc : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected CheckBoxList CBLFlag;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        private PublicFun publicFun_0 = new PublicFun();
        protected TextBox txtRubricDoc;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string strSql = "";
            if (this.int_0 != 0)
            {
                strSql = string.Concat(new object[] { "update ZiRubricInfo set RubricDoc='", this.publicFun_0.CheckString(this.txtRubricDoc.Text), "',InputUser='", this.httpCookie_1.Value, "',InputTime=getdate() where ID=", this.int_0 });
                this.publicFun_0.ExecuteSql(strSql);
                this.CBLFlag.SelectedIndex = -1;
                this.txtRubricDoc.Text = "";
                base.Response.Write("<script>alert('编辑打字试题库操作成功！');window.opener.location.href='RubricList.aspx';window.close();</script>");
            }
            else
            {
                for (int i = 0; i < this.CBLFlag.Items.Count; i++)
                {
                    if (this.CBLFlag.Items[i].Selected)
                    {
                        strSql = "insert into ZiRubricInfo(RubricDoc,InputUser,Flag) values('" + this.publicFun_0.CheckString(this.txtRubricDoc.Text) + "','" + this.httpCookie_1.Value + "','" + this.CBLFlag.Items[i].Value + "')";
                        this.publicFun_0.ExecuteSql(strSql);
                    }
                }
                this.CBLFlag.SelectedIndex = -1;
                this.txtRubricDoc.Text = "";
                base.Response.Write("<script>alert('添加打字试题库操作成功！');window.opener.location.href='RubricList.aspx';</script>");
            }
        }

        private void method_0()
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlDataReader reader = new SqlCommand("select * from ZiRubricInfo where ID=" + this.int_0, connection).ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                this.CBLFlag.SelectedIndex = -1;
                this.CBLFlag.Enabled = false;
                this.CBLFlag.Items.FindByValue(reader["Flag"].ToString()).Selected = true;
                this.txtRubricDoc.Text = reader["RubricDoc"].ToString();
            }
            reader.Close();
            connection.Close();
            connection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) == 0x3a)
                {
                    base.Response.Write("<script>alert('该版本为特惠版，此功能未开放！')</script>");
                }
                else if (!base.IsPostBack)
                {
                    if (!(this.publicFun_0.GetValues("select ZiManag from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "ZiManag") != "Y"))
                    {
                        this.butDefault.Visible = true;
                    }
                    else
                    {
                        this.butDefault.Visible = false;
                        base.Response.Write("<script>alert('打字参数设置权限未开放！')</scritp>");
                    }
                    if (this.int_0 != 0)
                    {
                        this.method_0();
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

